// (C) Copyright to Kevin. Applied to MIT LICENSE

#include "TextureManager.h"

#include "BlockWorld.h"

TextureManager::TextureManager()
{
	textures_color = new TMap<FString, TextureInfo>();
	textures_normal = new TMap<FString, TextureInfo>();
	textures_specular = new TMap<FString, TextureInfo>();
}

TextureManager::~TextureManager()
{
	delete textures_color;
	delete textures_normal;
	delete textures_specular;
}

void TextureManager::Initialize()
{
	textures_color->Add(FString("stone"), TextureInfo{ 0.0000f, 1.0000f, 0.2500f, 0.7500f });
	textures_color->Add(FString("dirt"), TextureInfo{ 0.2520f, 1.0000f, 0.5020f, 0.7500f });
	textures_color->Add(FString("grass_top"), TextureInfo{ 0.5039f, 1.0000f, 0.7539f, 0.7500f });
	textures_color->Add(FString("grass_side"), TextureInfo{ 0.0000f, 0.7480f, 0.2500f, 0.4980f });

	textures_normal->Add(FString("stone"), TextureInfo{ 0.0000f, 1.0000f, 0.2500f, 0.7500f });
	textures_normal->Add(FString("dirt"), TextureInfo{ 0.2520f, 1.0000f, 0.5020f, 0.7500f });
	textures_normal->Add(FString("grass_top"), TextureInfo{ 0.5039f, 1.0000f, 0.7539f, 0.7500f });
	textures_normal->Add(FString("grass_side"), TextureInfo{ 0.0000f, 0.7480f, 0.2500f, 0.4980f });

	textures_specular->Add(FString("stone"), TextureInfo{ 0.0000f, 1.0000f, 0.2500f, 0.7500f });
	textures_specular->Add(FString("dirt"), TextureInfo{ 0.2520f, 1.0000f, 0.5020f, 0.7500f });
	textures_specular->Add(FString("grass_top"), TextureInfo{ 0.5039f, 1.0000f, 0.7539f, 0.7500f });
	textures_specular->Add(FString("grass_side"), TextureInfo{ 0.0000f, 0.7480f, 0.2500f, 0.4980f });
}

TextureInfo* TextureManager::GetTexture(FString name, int type)
{
	switch (type) {
	case TEXTURE_TYPE_COLOR:
		return textures_color->Find(name);
	case TEXTURE_TYPE_NORMAL:
		return textures_normal->Find(name);
	case TEXTURE_TYPE_SPECULAR:
		return textures_specular->Find(name);
	default:
		UE_LOG(BlockEngine, Log, TEXT("Invalid texture type %i! "), type);
		return nullptr;
	}
}
